package com.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.constant.MessageConstant;
import com.constant.RedisMessageConstant;
import com.exception.CustomException;
import com.pojo.Order;
import com.pojo.Setmeal;
import com.result.Result;
import com.service.OrderService;
import com.utils.ValidateCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Map;

@RestController
@RequestMapping("/Order")
public class OrderController {

    @Autowired
    private JedisPool jedisPool;

    @Reference
    private OrderService orderService;


    @PostMapping("/findById")
    public Result findById(Integer id){
        try {
            Order order = orderService.findById(id);
            return new Result(true, MessageConstant.QUERY_ORDER_SUCCESS,order);
        }catch (Exception e){

        }
        return new Result(false, MessageConstant.QUERY_ORDER_FAIL);
    }


    @PostMapping("/submit")
    public Result submit(@RequestBody Map orderInfo) {
        Result valid = ValidateCodeUtils.isValid(jedisPool, orderInfo, RedisMessageConstant.SENDTYPE_ORDER);
        if(!valid.isFlag()){
            return valid;
        }
        //相等，
        Result result = orderService.doOrder(orderInfo);
        return result;
    }



}
